*Create time averages of inaction rates;
clear all
cd /OEUS/users/FEDSusers/QCEW/revision_2024/Output

foreach x in _allq _allq_over20 _allq_wgt_over20 _allq_wgt _allq_et _allq_et_wgt _allq_et_over20 _allq_et_wgt_over20 {
import sas using inactionrate`x', clear
sort year qrt yearlst qrtlst
by year qrt: gen quart= _n
keep if quart<=16
collapse (mean) inactive inactive11 inactive22 empavg empavg11 empavg22 (rawsum) N=_FREQ_ [aw=_FREQ_], by(quart)
outsheet using inaction`x'_ave.csv, c replace
}

*By size group
foreach y in _allq _allq_wgt{
import sas using inactionrate_bysizegrp`y', clear
sort size year qrt yearlst qrtlst
by size year qrt: gen quart= _n
keep if quart<=16
collapse (mean) inactive inactive11 inactive22 empavg empavg11 empavg22 (rawsum) N=_FREQ_ [aw=_FREQ_], by(quart size)
rename inactive* inactive*_ 
rename empavg* empavg*_
rename N* N*_
reshape wide inactive_ inactive11_ inactive22_ empavg_ empavg11_ empavg22_ N_, i(quart) j(size)

foreach x in inactive_ inactive11_ inactive22_ empavg_ empavg11_ empavg22_ N_{
	rename `x'1 `x'1_14
	rename `x'2 `x'14_42
	rename `x'3 `x'43_116
	rename `x'4 `x'117_381 
	rename `x'5 `x'382p
}
outsheet using inaction`y'_bysizegrp_ave.csv, c replace
}
